//
// Description: 5903. 简易银行系统
// Created by Loading on 2021/10/17.
//

#include <bits/stdc++.h>

using namespace std;

class Bank {
public:
    explicit Bank(vector<long long> &balance) {
        count = balance.size();
        for (int i = 0; i < count; ++i) {
            m[i + 1] = balance[i];
        }
    }

    bool transfer(int account1, int account2, long long money) {
        // 无账户或余额不足
        if (account1 > count || account2 > count || m[account1] < money) {
            return false;
        }
        m[account1] -= money;
        m[account2] += money;

        return true;
    }

    bool deposit(int account, long long money) {
        // 无账户
        if (account > count) {
            return false;
        }
        m[account] += money;

        return true;
    }

    bool withdraw(int account, long long money) {
        // 无账户或余额不足
        if (account > count || m[account] < money) {
            return false;
        }
        m[account] -= money;

        return true;
    }

private:
    // <账户，余额>
    map<int, long long> m;
    // 账户数目
    int count;
};

int main() {
    vector<long long> balance = {10, 100, 20, 50, 30};
    Bank *bank = new Bank(balance);
    bool param_1 = bank->withdraw(3, 10);
    bool param_2 = bank->transfer(5, 1, 20);
    bool param_3 = bank->deposit(5, 20);
    bool param_4 = bank->transfer(3, 4, 15);
    bool param_5 = bank->withdraw(10, 15);
    cout << param_1 << ' ' << param_2 << ' ' << param_3 << ' ' << param_4 << ' ' << param_5 << endl;

    return 0;
}